package day5;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class Demo5 {

    public static class User{
        String username;
        String password;

//        public User(){}

//        public User(String username, String password){
//            this.username = username;
//            this.password = password;
//        }

        @Override
        public String toString() {
            return "User{" +
                    "username='" + username + '\'' +
                    ", password='" + password + '\'' +
                    '}';
        }
    }

    public static void main(String[] args) {

        int n = 6;
        User[] list = new User[n];

        for (int i = 0; i < n; i++){

            list[i] = new User();
//            list[i] = new User(name(), code());
            list[i].username = name();
            list[i].password = code();
        }

        Scanner scanner = new Scanner(System.in);

        for (User user : list) {
            System.out.println("用户名:" + user.username + "  密码:" + user.password);
        }

        System.out.println("请输入你的用户名和密码:");
        String username = scanner.nextLine();
        String password = scanner.nextLine();

        for (User user : list) {
            if (user.username.equals(username)&& user.password.equals(password))
                System.out.println("用户名和密码都正确");
            else System.out.println(user.username +"输入不正确");
        }
    }

    private static String code() {
        Random r = new Random();
        String name = "";
        for (int i = 0; i < 6; i++){
            char a = (char)(r.nextInt(10) + 48);
            name += a;
        }
        return name;
    }

    public static String name(){

        Random random = new Random();
        String name = "";
        for (int i = 0; i < 5; i++){
            char a = (char)(random.nextInt(26) + 65);
            name += a;
        }
        return name;
    }
}
